package com.gwcloud.leetcode.offers;

import com.gwcloud.leetcode.common.datastructure.ListNode;

/** 
* @ClassName   : Leetcode0060 
* @author      : ganwei 
* @date        : 2020年5月31日 
* @Description : 面试题06. 从尾到头打印链表 
*/
public class Leetcode0060 {
    public int[] reversePrint(ListNode head) {
    	int len = 0;
    	ListNode index = head;
    	while(index != null) {
    		len++;
    		index = index.next;
    	}
    	int[] nums = new int[len];
    	buildList(head, nums, len-1);
    	return nums;
    	
    }
    
    /**
     * -递归构建
     */
    public void buildList(ListNode head, int[] nums, int index) {
    	if(head == null) {
    		return;
    	}
    	buildList(head.next, nums, index-1);
    	nums[index] = head.val;
    }
    
    /**
     * -主函数
     */
    public static void main(String[] args) {
    	
    }
}
